package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Reg Servlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        PrintWriter pw = response.getWriter();
        String uname = request.getParameter("userName");
        String pass = request.getParameter("passWord");
        pw.print(uname + "，hello!");
        Users user = new Users();

        user.setEu_user_name(uname);
        user.setEu_password(pass);
//未使用工厂类---------
        UserDao userDao = new UserDao();
        boolean i = false ;
        i = userDao.insert(user);

        if (i){
            System.out.println("成功");
            pw.print(uname + "-------1111");
        }else{
            System.out.println("失败");
            pw.print(pass + "---------0000");
        }

    }
}
